#define _CRT_SECURE_NO_WARNINGS 1
#include<iostream>
#include<cmath>
using namespace std;
using ll = long long;
using pll = pair<ll, ll>;
ll n, a, b;
int t;
pll get(ll n, ll a)
{
    if (n == 0) return { 0,0 };
    ll block = 1ll << 2 * n - 2, len = 1ll << n - 1;
    int z = a / block;
    pll p = get(n - 1, a % block);
    ll x = p.first, y = p.second;
    if (z == 0) return { y,x };
    else if (z == 1) return { x,y + len };
    else if (z == 2) return { x + len,y + len };
    return { len * 2 - 1 - y,len - x - 1 };
}
int main()
{
    cin >> t;
    while (t--)
    {
        cin >> n >> a >> b;
        pll z1 = get(n, a - 1);
        pll z2 = get(n, b - 1);
        ll dx = z1.first - z2.first;
        ll dy = z1.second - z2.second;
        double dist = sqrt(dx * dx + dy * dy) * 10;
        printf("%.0lf\n", dist);
    }
    return 0;
}